<script lang="ts">
import {defineComponent} from 'vue'
import {RouteLocationNormalizedLoaded} from "vue-router";
import fileReq from "@/api/file";
import {FileUtils} from "@/utils/FileUtils";
import {ElMessageBox} from "element-plus";

export default defineComponent({
  name: "ShowShareFile",
  computed: {
    id() {
      let $route = this.$route as RouteLocationNormalizedLoaded;
      return $route.params.id
    }
  },
  data(){
    return {
      data:{} as any,
    }
  },
  created() {
    fileReq.getShareFile(this.id).then(res=>{
      this.data = res.data
    })
  },
  methods:{
    shareFileDown() {
      ElMessageBox.confirm("开始下载？", "下载").then(()=>{
        fileReq.shareFileDown(this.data).then(res=>{
          FileUtils.fileDownLoadFromUrl(
            fileReq.getDownloadFileOrDirById(res.data.downloadFileId),
            res.data.downloadName)
        })
      })
    }
  }
})
</script>

<template>
  <div>
    <div>分享人：{{data.username}}</div>
    <div>分享结束时间：{{data.entTime}}</div>
    <div>分享文件：{{data.filePath}}</div>
    <div>
      <el-button
        @click="shareFileDown"
      >下载</el-button>
    </div>
  </div>
</template>

<style scoped lang="scss">

</style>
